<?php

namespace api\applets\controller;

use \cmf\controller\RestBaseController;
use think\Db;

/**
 * 商城
 * Class ShoppingMallController
 * @package api\applets\controller
 */
class ShoppingMallController extends RestBaseController
{
    /**
     * 商品服务列表
     * 根据商品类型查询
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function getGoodsList()
    {
        $requst = $this->request;
        $cate_p_id = $requst->param("cate_p_id");
        $list_rows = $requst->param("list_rows");
//        $userId = $requst->param("userId");
//        $token = $requst->param("token");
//        $this->LogInOrNot($userId, $token);
        $data = Db::name("goods")->field("id,goods_name,price,photos_url")
            ->where("cate_p_id", $cate_p_id)
            ->where("if_show", "1")
            ->where("is_delete", "0")
            ->where("type", "0")
            ->paginate($list_rows, false, ['query' => request()->param()]);
        if (!empty($data)) {
            $response = ['list' => $data];
        } else {
            $response = $data;
        }
//        $page = Db::name("null")
//            ->paginate();
//        $page->render();
//        $json = array('code'=>1,'msg'=>"请求成功！",'data'=>$response);
//        exit(\GuzzleHttp\json_encode($json));
        $this->success("请求成功！", $response);
    }
    /**
     * 获取商品类型
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function getGoodsTypeList()
    {
//        $requst = $this->request;
//        $userId = $requst->param("userId");
//        $token = $requst->param("token");
//        $this->LogInOrNot($userId, $token);
        $data = Db::name("cate")->field("id,cate_name,path")->where("type", "2")
            ->where("is_delete", "0")
            ->where("if_show", "1")
            ->select();
        $this->success("请求成功！", $data);
    }
}